var prefix = "/yw/appraisalApply";

$(document).ready(function () {
    validateRule();
});

$.validator.setDefaults({
    submitHandler: function () {
        update();
    }
});

function update() {

    var amount = $('#amount').val();
    if (amount <= 0) {
        return layer.msg("指标数量不能小于1");
    }
    $.ajax({
        type: "POST",
        url: prefix + "/applyEdit",
        data: {
            id: $('#id').val(),
            amount: $('#amount').val(),
            state: $('input[name="state"]:checked').val(),
            stateName: $('input[name="state"]:checked').parent("label").text().trim(),
            checkMessage: $('#checkMessage').val()
        },
        async: false,
        error: function () {
            parent.layer.alert("网络超时");
        },
        success: function (data) {
            if (data.code === 0) {
                parent.layer.msg("操作成功");
                parent.reLoad();
                var index = parent.layer.getFrameIndex(window.name);
                parent.layer.close(index);
            } else {
                parent.layer.alert(data.msg)
            }
        }
    });
}

function validateRule() {
    var icon = "<i class='fa fa-times-circle'></i> ";
    $("#applyForm").validate({
        rules: {
            amount: {
                required: true
            }
            , state: {
                required: true
            }
            , checkMessage: {
                required: true
            }
        },
        messages: {
            amount: {
                required: icon + "审核信息"
            }
            , state: {
                required: icon + "选择审核结果"
            }
            , checkMessage: {
                required: icon + "审核意见不能为空"
            }
        }
    })
}
